package com.whut.customer.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.whut.customer.dao.PlaneListMapper;
import com.whut.customer.entity.Plane;
import com.whut.customer.service.IPlaneListService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.text.DecimalFormat;
import java.util.List;

/**
 * <p>
 * 机型表 服务实现类
 * </p>
 *
 * @author author
 * @since 2021-04-12
 */
@Service
public class PlaneListServiceImpl extends ServiceImpl<PlaneListMapper, Plane> implements IPlaneListService {

    @Override
    public Plane findPlane(float left, float right){
        Plane result=new Plane();
        float deviation = 45.0f - left - right;
        result.setMainDistance(deviation);
        System.out.println("飞机主轮距:" +deviation+"米\n");
        float minMainDistance = deviation-0.1f;
        float maxMainDistance = deviation+0.1f;
        float deviation2 = 45.0f - left - right;
        if(left <= right){
            deviation2 = deviation2 / 2.0f - (22.5f - right);
            DecimalFormat decimalFormat = new DecimalFormat(".00");
            String p = decimalFormat.format(deviation2);
            result.setDeviation("往东偏移" + p + "米");
        }
        else{
            deviation2 = deviation2 / 2.0f - (22.5f - left);
            DecimalFormat decimalFormat = new DecimalFormat(".00");
            String p = decimalFormat.format(deviation2);
            result.setDeviation("往西偏移" + p + "米");
        }
        List<Plane> planeList = baseMapper.findPlane(minMainDistance, maxMainDistance);
        if (!CollectionUtils.isEmpty(planeList)) {
            Plane plane = planeList.get(0);
            plane.setDeviation(result.getDeviation());
            return plane;
        } else
            return result;
    }
}
